//
//  QEditChargeBookVC.m
//  QoilPublic
//
//  Created by 杨凯 on 16/8/16.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QEditChargeBookVC.h"
#import "QPayOutVC.h"
#import "QIncomeVC.h"
@interface QEditChargeBookVC ()

@property(nonatomic,strong)UISegmentedControl *segCtrl;

@end
@implementation QEditChargeBookVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationItem.titleView = self.segCtrl;
    [self addController];
    
    if(!_model){//如果没有数据
        QPayOutVC *vc1 = (QPayOutVC *)self.childViewControllers[0];
        vc1.outStyle = QPayOutVCNotHaveDataStyle;
        vc1.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
        [self.view addSubview:vc1.view];
        
        QIncomeVC *vc2 = (QIncomeVC *)self.childViewControllers[1];
        vc2.comeStyle = QIncomeVCNotHaveDataStyle;
    }else if (_model && [_model.accountTypeBean.accountTypeId isEqualToString:@"0"]){//支出
        QPayOutVC *vc1 = (QPayOutVC *)self.childViewControllers[0];
        vc1.typeStr = _model.accountUseTypeBean.useTypeName;
        vc1.typeId = _model.accountUseTypeBean.useTypeId;
        vc1.moneyStr = _model.accountMoneyTypeBean.moneyTypeName;
        vc1.moneyId = _model.accountMoneyTypeBean.moneyTypeId;
        vc1.str = _model.accountTypeBean.money;
        vc1.year = _model.year;
        vc1.month = _model.month;
        vc1.week = _model.week;
        vc1.day = _model.day;
        vc1.time = _model.time;
        vc1.accountIdStr = _model.accountId;
        vc1.createTime = _model.createTime;
        vc1.descStr = _model.remark;
        vc1.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
        vc1.outStyle = QPayOutVCHaveDataStyle;
        [self.view addSubview:vc1.view];
        
        QIncomeVC *vc2 = (QIncomeVC *)self.childViewControllers[1];
        vc2.typeStr = @"工程款";
        vc2.typeId = @"1";
        vc2.moneyStr = _model.accountMoneyTypeBean.moneyTypeName;
        vc2.moneyId = _model.accountMoneyTypeBean.moneyTypeId;
        vc2.str = _model.accountTypeBean.money;
        vc2.year = _model.year;
        vc2.month = _model.month;
        vc2.week = _model.week;
        vc2.day = _model.day;
        vc2.time = _model.time;
        vc2.accountIdStr = _model.accountId;
        vc2.createTime = _model.createTime;
        vc2.descStr = _model.remark;
        vc2.comeStyle = QIncomeVCHaveDataStyle;
        
    }else if (_model && [_model.accountTypeBean.accountTypeId isEqualToString:@"1"]){//收入
        QIncomeVC *vc1 = (QIncomeVC *)self.childViewControllers[1];
        vc1.typeStr = _model.accountUseTypeBean.useTypeName;
        vc1.typeId = _model.accountUseTypeBean.useTypeId;
        vc1.moneyStr = _model.accountMoneyTypeBean.moneyTypeName;
        vc1.moneyId = _model.accountMoneyTypeBean.moneyTypeId;
        vc1.str = _model.accountTypeBean.money;
        vc1.year = _model.year;
        vc1.month = _model.month;
        vc1.week = _model.week;
        vc1.day = _model.day;
        vc1.time = _model.time;
        vc1.accountIdStr = _model.accountId;
        vc1.createTime = _model.createTime;
        vc1.descStr = _model.remark;
        vc1.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
        vc1.comeStyle = QIncomeVCHaveDataStyle;
        [self.view addSubview:vc1.view];
        
        QPayOutVC *vc2 = (QPayOutVC *)self.childViewControllers[0];
        vc2.typeStr = @"工程费用-燃油费用";
        vc2.typeId = @"11";
        vc2.moneyStr = _model.accountMoneyTypeBean.moneyTypeName;
        vc2.moneyId = _model.accountMoneyTypeBean.moneyTypeId;
        vc2.str = _model.accountTypeBean.money;
        vc2.year = _model.year;
        vc2.month = _model.month;
        vc2.week = _model.week;
        vc2.day = _model.day;
        vc2.time = _model.time;
        vc2.accountIdStr = _model.accountId;
        vc2.createTime = _model.createTime;
        vc2.descStr = _model.remark;
        vc2.outStyle = QPayOutVCHaveDataStyle;
    }
}

- (void)addController {
    QPayOutVC *vc1 = [[QPayOutVC alloc]init];
    vc1.view.backgroundColor = [QColorUtility defaultBackGroundColor];
    [self addChildViewController:vc1];
    
    QIncomeVC *vc2 = [[QIncomeVC alloc]init];
    vc2.view.backgroundColor = [QColorUtility defaultBackGroundColor];
    [self addChildViewController:vc2];
    
}

- (UISegmentedControl*)segCtrl {
    if (!_segCtrl) {
        _segCtrl = [[UISegmentedControl alloc]initWithItems:@[@"支出",@"收入"]];
        _segCtrl.frame = CGRectMake(0, 0, kScreenWidth-200, 30);
        _segCtrl.tintColor = [UIColor whiteColor];
        if(!_model){//如果没有数据
            _segCtrl.selectedSegmentIndex = 0;
        }else if (_model && [_model.accountTypeBean.accountTypeId isEqualToString:@"0"]){//支出
            _segCtrl.selectedSegmentIndex = 0;
        }else if (_model && [_model.accountTypeBean.accountTypeId isEqualToString:@"1"]){//收入
            _segCtrl.selectedSegmentIndex = 1;
        }
        [_segCtrl addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    }
    return _segCtrl;
}

- (void)segAction:(UISegmentedControl*)sender {
    [[UIApplication sharedApplication].keyWindow endEditing:NO];
    UIViewController *selectedVC = self.childViewControllers[sender.selectedSegmentIndex];
    if (!selectedVC.view.superview) {
        selectedVC.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
        [self.view addSubview:selectedVC.view];
    }
    [self.view bringSubviewToFront:selectedVC.view];
}

@end
